//
//  UserInfoView.m
//  CharlesMVX
//
//  Created by Charles on 2020/3/11.
//  Copyright © 2020 Charles. All rights reserved.
//

#import "UserInfoView.h"
#import "Masonry.h"

@interface UserInfoView()

@property (nonatomic, strong) UIButton *headImageBtn;   // 头像
@property (nonatomic, strong) UILabel *nameLabel;       // 姓名
@property (nonatomic, strong) UILabel *blogCountLabel;  // 作品
@property (nonatomic, strong) UILabel *friendsCntLabel; // 好友数
@property (nonatomic, strong) UILabel *summaryLabel;    // 简介

@end

@implementation UserInfoView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupSubViews];
    }
    return self;
}

- (void)setupSubViews {
    [self addSubview:self.headImageBtn];
    [self addSubview:self.nameLabel];
    [self addSubview:self.blogCountLabel];
    [self addSubview:self.friendsCntLabel];
    [self addSubview:self.summaryLabel];
    
    [self.headImageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.inset(40);
        make.width.height.mas_equalTo(80);
        make.centerX.equalTo(self.mas_centerX);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(20);
        make.top.equalTo(self.headImageBtn.mas_bottom).offset(20);
        make.height.mas_equalTo(20);
    }];
    
    [self.blogCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(10);
        make.left.inset(80);
        make.right.equalTo(self.friendsCntLabel.mas_left).offset(-50);
        make.height.mas_equalTo(20);
    }];
    
    [self.friendsCntLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.blogCountLabel.mas_right).offset(50);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(10);
        make.right.inset(80);
        make.height.mas_equalTo(20);
        make.width.equalTo(self.blogCountLabel.mas_width);
    }];
    
    [self.summaryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.friendsCntLabel.mas_bottom).offset(10);
        make.left.right.inset(40);
        make.bottom.equalTo(self.mas_bottom).offset(-40);
    }];
}


- (void)setName:(NSString *)name {
    self.nameLabel.text = name;
}

- (void)setBlogCnt:(NSString *)blogCnt{
    self.blogCountLabel.text = blogCnt;
}

- (void)setFriendsCnt:(NSString *)friendCnt {
    self.friendsCntLabel.text = friendCnt;
}

- (void)setSummary:(NSString *)summary {
    self.summaryLabel.text = summary;
}

- (void)setHeadImage:(UIImage *)image {
    [self.headImageBtn setImage:image forState:UIControlStateNormal];
}

- (void)addTarget:(id)target selector:(SEL)selector{
    [self.headImageBtn addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
}


- (UIButton *)headImageBtn {
    if (!_headImageBtn) {
        _headImageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _headImageBtn;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = [UIFont systemFontOfSize:15];
        _nameLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _nameLabel;
}

- (UILabel *)blogCountLabel {
    if (!_blogCountLabel) {
        _blogCountLabel = [[UILabel alloc]init];
        _blogCountLabel.font = [UIFont systemFontOfSize:15];
        _blogCountLabel.textAlignment = NSTextAlignmentRight;
    }
    return _blogCountLabel;
}

- (UILabel *)friendsCntLabel {
    if (!_friendsCntLabel) {
        _friendsCntLabel = [[UILabel alloc]init];
        _friendsCntLabel.font = [UIFont systemFontOfSize:15];
        _friendsCntLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _friendsCntLabel;
}

- (UILabel *)summaryLabel {
    if (!_summaryLabel) {
        _summaryLabel = [[UILabel alloc]init];
        _summaryLabel.font = [UIFont systemFontOfSize:15];
        _summaryLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _summaryLabel;
}

@end
